package com.dq.domain.goods;

import com.dq.vo.baseVo.VO;
import com.dq.vo.baseVo.VO.ToVO;
import com.dq.domain.base.BaseEntity;
import com.dq.domain.category.Attributes;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;

/**
 * @创建人 gewenzhen
 * @创建时间 2019/9/16
 * @描述
 */
@Data
@Entity
@ApiModel(value = "商品属性")
public class GoodAttributes extends BaseEntity implements ToVO {
    @ApiModelProperty(value = "商品",hidden = true)
    @ManyToOne
    protected Goods goods;
    @ApiModelProperty(value = "属性",hidden = true)
    @ManyToOne
    protected Attributes attributes;
    @ApiModelProperty("值")
    protected String value;
    @ApiModelProperty("排序")
    protected Long sortNo;

    @Data
    @ApiModel(value = "商品属性视图")
    public static class Vo implements VO {
        @ApiModelProperty("id")
        private Long id;
        @ApiModelProperty(value = "商品id")
        private Long goodsId;
        @ApiModelProperty(value = "属性名")
        private String attributesName;
        @ApiModelProperty("属性值")
        private String value;
        @ApiModelProperty("排序")
        private Long sortNo;
    }

    @Override
    public VO toVO(boolean isRecursion) {
        Vo vo = new Vo();
        vo.id = this.id;
        vo.goodsId = this.goods == null ? null : this.goods.getId();
        vo.attributesName = this.attributes == null ? "" : this.attributes.getName();
        vo.value = this.value;
        vo.sortNo = this.sortNo;
        return vo;
    }
}
